//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef _BL_FTUART_H
#define _BL_FTUART_H

//??#ident "$Id: ftuart.h,v 1.1.2.1 2006/10/10 10:30:48 zhangyi Exp $"

#include "types.h"
#include "bulverde.h"

#define FFRBR __REG(FFUART_BASE_PHYSICAL+FF_RBR_OFFSET)
#define FFTHR __REG(FFUART_BASE_PHYSICAL+FF_THR_OFFSET)
#define FFIER __REG(FFUART_BASE_PHYSICAL+FF_IER_OFFSET)
#define FFIIR __REG(FFUART_BASE_PHYSICAL+FF_IIR_OFFSET)
#define FFFCR __REG(FFUART_BASE_PHYSICAL+FF_FCR_OFFSET)
#define FFLCR __REG(FFUART_BASE_PHYSICAL+FF_LCR_OFFSET)
#define FFMCR __REG(FFUART_BASE_PHYSICAL+FF_MCR_OFFSET)
#define FFLSR __REG(FFUART_BASE_PHYSICAL+FF_LSR_OFFSET)
#define FFMSR __REG(FFUART_BASE_PHYSICAL+FF_MSR_OFFSET)
#define FFSPR __REG(FFUART_BASE_PHYSICAL+FF_SPR_OFFSET)
#define FFDLL __REG(FFUART_BASE_PHYSICAL+FF_DLL_OFFSET)
#define FFDLH __REG(FFUART_BASE_PHYSICAL+FF_DLH_OFFSET)
#define FFISR __REG(FFUART_BASE_PHYSICAL+FF_ISR_OFFSET)
#define FFFOR __REG(FFUART_BASE_PHYSICAL+FF_FOR_OFFSET)
#define FFABR __REG(FFUART_BASE_PHYSICAL+FF_ABR_OFFSET)
#define FFACR __REG(FFUART_BASE_PHYSICAL+FF_ACR_OFFSET)

typedef enum { /* Some useful SA-1100 baud rates */
    baud1k2 = 192,
    baud9k6 = 96,
    baud19k2 = 48,
    baud38k4 = 24,
    baud57k6 = 16,
    baud115k2 = 8
} eBauds;

/* Function protos */
void ftuart_init(eBauds baudrate);

void ftuart_output_byte(const char c);
void ftuart_output_rawbyte(const char c);
void ftuart_output_string(const char *s);
void ftuart_output_hex(const u32 h);
void ftuart_output_byteinhex(const char c);
void ftuart_output_dec(const u32 d);
void ftuart_output_block(const char *buf, int bufsize);

int  ftuart_input_byte(char *c);
int  ftuart_input_str(char *buf, int count);
int  ftuart_input_string(char *s, const int len, const int timeout);
int  ftuart_input_block(char *buf, int bufsize, const int timeout);
void  ftuart_input_flush(void);

int ftuart_clear_rx(void);
#if 0//DEBUG
#define Debug_outputString(x) buart_output_string(x)
#define Debug_outputByte(x) buart_output_byte(x)
#define Debug_outputHex(x) buart_output_hex(x)
#define Debug_outputByteInHex(x) buart_output_byteinhex(x)
#define Debug_outputDec(x) buart_output_dec(x)
//#else
#define Debug_outputString(x)
#define Debug_outputByte(x)
#define Debug_outputHex(x)
#define Debug_outputByteInHex(x)
#define Debug_outputDec(x)
#endif

#endif
